﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
//using facebook.desktop;
using facebook.Schema;
using facebook.test.Properties;
using facebook.desktop;

namespace facebook.test
{
	public partial class FriendViewer : Form
	{
		public FriendViewer()
		{
			InitializeComponent();
			facebookService1.ApplicationKey = Settings.Default.api_key;
			facebookService1.Secret = Settings.Default.secret;
			facebookService1.ConnectToFacebook();
		}

		private void TestService_Load(object sender, EventArgs e)
		{
			ListenToEvents(true);
			try
			{
				var friends = facebookService1.friends.getUserObjects();
				var me = facebookService1.users.getInfo();
				LoadUserBasedControls(me);
				friendList1.Friends = friends;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				Close();
			}
		}

		private void ListenToEvents(bool listen)
		{
			if (listen)
			{
				friendList1.FriendSelected += friendList1_FriendSelected;
			}
		}

		private void friendList1_FriendSelected(object sender, FriendSelectedEventArgs e)
		{
			LoadUserBasedControls(e.User);
		}

		private void LoadUserBasedControls(user user)
		{
			profile1.User = user;
		    photoAlbum1.Albums = facebookService1.photos.getAlbums(user.uid);
		}
	}
}